package com.xuetang9.fujian.socketdemo;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * @author: fujian
 * @description:
 * @date: 2021/5/9 11:05
 * @version: V1.0
 * @package: com.xuetang9.fujian.socketdemo
 **/
public class UrlDemo {
    public static void main(String[] args) throws IOException {
        String urlStr = "www.baidu.com";
        URL url = new URL("http","www.baidu.com",80,"/s?wd=云台山&wd1=嵩山");
        System.out.println("协议：" + url.getProtocol());
        System.out.println("主机：" + url.getHost());
        System.out.println("端口：" + url.getPort());
        System.out.println("文件路径：" + url.getPath());
        System.out.println("文件名：" + url.getFile());
        System.out.println("相对路径：" + url.getRef());
        System.out.println("查询字符串：" + url.getQuery());
        InputStream inStream = url.openStream();
        BufferedReader reader = new BufferedReader(new InputStreamReader(inStream));
        String line = null;
        while ((line = reader.readLine()) != null){
            System.out.println(line);
        }
    }
}
